package IOtest;

import static java.lang.Thread.*;

class MyRunnable01 implements Runnable{
    /*
    重写run()方法
     */
    @Override
    public void run() {
        while(true){
            System.out.println(Thread.currentThread().getName()+":run()方法在运行");
            try{
                Thread.sleep(1000);
            }catch(InterruptedException e){
                e.printStackTrace();
            }
        }
    }
}
public class ThreadTest1 {
    public static void main(String[] args) throws InterruptedException {
        MyRunnable01 mr=new MyRunnable01();
        //创建两个线程对象
        Thread t1=new Thread(mr,"Thread 1");
        Thread t2=new Thread(mr,"Thread 2");
        //启动线程
        t1.start();
        t2.start();
        //在主方法中执行while循环
        while(true){
            System.out.println("main()方法在运行");
            Thread.sleep(1000);
        }
    }
}
